/*
 * WidgetWidgetContainer.cpp
 *
 *  Created on: Jun 18, 2012
 *      Author: gonzalo
 */

#include "WidgetContainer.h"

WidgetContainer::WidgetContainer(int posX, int posY,SDL_Surface* surface, Widget *parent)
:Widget(posX, posY,surface, parent){}

void WidgetContainer::add(Widget *widget){
	widgets.push_back(widget);
}

void WidgetContainer::showOn(SDL_Surface* surface) {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->showOn(surface);
	}
}

void WidgetContainer::handleEvent(Event event) {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->handleEvent(event);
	}
}

void WidgetContainer::resolve() {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->resolve();
	}
}


WidgetContainer::~WidgetContainer() {
	while(!widgets.empty()){
		delete widgets.back();
		widgets.pop_back();
	}
}

